<template>
  <div class="form-view-row base-address-view">
    <label>{{field.displayName}}</label>
    <div class="form-view-row-content">
      <el-button type="text" @click="jump">{{ title }}</el-button>
    </div>
  </div>
</template>
  
<script>
import { openTabForWikiCreate, openTabForWikiView } from '@src/util/business/openTab'
import { getDocumentList } from '@src/api/Repository'
export default {
  name: 'FormSelectViewKnowledge',
  props: {
    field: {
      type: Object,
      default: () => ({})
    },
    value: String
  },

  data(){
    return {
      wikiList:[],
      title:'',
    }
  },

  watch: {
    value:{
      deep: true,
      handler(val){
        console.log(123,val)
        if(!val){
          this.title = '';
          return;
        }
        this.getTitle()
      }
    },

    wikiList:{
      deep:true, //true为进行深度监听,false为不进行深度监听
      handler(val){
        console.log(234,val)
        this.getTitle()
      }
    }
  },

  mounted(){
    this.getData()
  },

  methods:{
    getData(){
      // 先不允许分页，所以pageSize调了一个大值
      let params = {
        pageNum: 1,
        pageSize: 1000
      }
      getDocumentList(params).then(result => {
        if (result.success) {
          this.wikiList = result?.result?.list || [];
        }
      })
    },

    getTitle(){
      console.log(this.value)
      this.wikiList.map(item => {
        if(item.id === this.value){
          this.title = item.title
          return
        }
      })
    },

    jump(){
      openTabForWikiView(this.value)
    }
  }
}
</script>